package com.zhan.drugStore.controller;


import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.zhan.drugStore.bean.entity.Inventory;
import com.zhan.drugStore.bean.entity.User;
import com.zhan.drugStore.bean.form.InventorySearch;
import com.zhan.drugStore.bean.form.UserForm;
import com.zhan.drugStore.bean.form.UserSearch;
import com.zhan.drugStore.bean.vo.InventoryVO;
import com.zhan.drugStore.bean.vo.UserVO;
import com.zhan.drugStore.util.BeanUtils;
import com.zhan.drugStore.util.ResponseBase;
import com.zhan.drugStore.util.ResponseBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zy
 * @since 2024-07-24
 */
@RestController
@RequestMapping("/user")
public class UserController extends SuperController{

    @PostMapping("/addOrUpdate")
    @ApiOperation("新增或修改")
    public ResponseBase addOrUpdate(@RequestBody UserForm userForm) {
        super.userService.addOrUpdate(userForm);
        return super.resultSuccess();
    }

    @PostMapping("/list")
    @ApiOperation("列表")
    public ResponseBean<PageInfo<UserVO>> userList(@RequestBody UserSearch form) {
        if(form.getPage() != null && form.getLimit() != null) {
            PageMethod.startPage(form.getPage(), form.getLimit());
        }
        return super.resultSuccess(new PageInfo<>(super.userService.userList(form)));
    }

    @GetMapping("/getUserById")
    @ApiOperation("单个查询")
    public ResponseBean<UserVO> getUserById(@RequestParam Long id) {
        return super.resultSuccess(BeanUtils.objToObj(super.userService.getById(id), UserVO.class));
    }

    @GetMapping("/getMatchUserList")
    @ApiOperation("为单个用户匹配")
    public ResponseBean<List<UserVO>> getMatchUserList(@RequestParam Long id) {
        return super.resultSuccess(userService.getMatchUserList(id));
    }
}

